package com.jz.digital.dialog

import android.content.Context
import android.graphics.drawable.BitmapDrawable
import android.view.LayoutInflater
import android.view.View
import android.widget.PopupWindow
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.jz.digital.R
import com.jz.digital.bean.ServerBean
import com.jz.digital.view.CommonRecyclerViewAdapter
import com.jz.digital.view.CommonRecyclerViewHolder
import com.jz.digital.view.MultiItemTypeAdapterForRV

/**
 * @author jiangdz
 * @date 2024/11/19
 * @time 20:45
 * 用途:
 */
object DialogUtil {
    fun getNormalPop(context: Context, dataList:List<ServerBean.GXInfo>, callback:(index:Int)->Unit):PopupWindow{
        val contentView=LayoutInflater.from(context).inflate(R.layout.dialog_normal_select_layout,null)
        val recycler=contentView.findViewById<RecyclerView>(R.id.recycler)
        val popupWindow=PopupWindow(context)
        popupWindow.contentView=contentView
        popupWindow.setBackgroundDrawable(BitmapDrawable())
        popupWindow.isOutsideTouchable=true
        popupWindow.isTouchable=true
        val adapter=object :CommonRecyclerViewAdapter<ServerBean.GXInfo>(context,R.layout.item_normal_select_layout,dataList){
            override fun convert(holder: CommonRecyclerViewHolder?, gtxInfo: ServerBean.GXInfo, position: Int) {
                if (holder==null)return
                val tv=holder.getView<TextView>(R.id.tv)
                tv.text=gtxInfo.basName
                holder.setVisible(R.id.image_line,position != dataList.size - 1)
            }
        }
        recycler.adapter=adapter
        adapter.setOnItemClickListener(object :MultiItemTypeAdapterForRV.OnItemClickListener{
            override fun onItemClick(view: View?, holder: RecyclerView.ViewHolder?, position: Int) {
                callback(position)
            }

            override fun onItemLongClick(
                view: View?,
                holder: RecyclerView.ViewHolder?,
                position: Int
            ): Boolean {
                return false
            }

        })
        return popupWindow
    }
}